#ifndef _EESD_H_
#define _EESD_H_
#include<system.h>

/************************************************************
 * This is the header file that goes with the starting
 * library routines that  Drive LCD display
 *        
 */


/*  LCD Routines
 *
 *  Notes: Board is setup for 4 bit data on the upper
 *  bits of port D. Control port is on poert E.0 and
 *  E.1. Note that the R/W is pulled to 0, so that only
 *  writing is done to the display.
 *  NOTE: Ports must be set digital before using the LCD display
 *  */

// Ports naming

#define LCD_DATA           latd   // LCD data port
#define LCD_E_port         late   // enable control port
#define LCD_RS_port        late   // register select port

// Control signals

#define LCD_E_bit       1    // LCD enable register
#define LCD_RS_bit      0    // LCD register select

// Some usefull macros. These set or clear the control
// or register select bits.

#define LCD_E_U     set_bit(LCD_E_port, LCD_E_bit)
#define LCD_E_D     clear_bit(LCD_E_port, LCD_E_bit)
#define LCD_RS_U    set_bit(LCD_RS_port, LCD_RS_bit)
#define LCD_RS_D    clear_bit(LCD_RS_port, LCD_RS_bit)

// Use nested macros

#define write_data  LCD_RS_U; LCD_E_U; LCD_E_D;  // RS=1, toggle enable bit
#define write_cmd   LCD_RS_D; LCD_E_U; LCD_E_D;  // RS=0, toggle enable bit

// Added by us:
// Serial port

void serial_init(void);
void putc(char a);
char getc(void);
void putstring( const char* text );
void putdec(unsigned short dat);
unsigned short getdec(void);
void puthex(char data);
void puthex(char* data);
void puthex(unsigned short data);
void puthex(short data);
void puthex(unsigned long data);
void putint(short dat);

// the end

// LCD Function prototypes 
void LCD_init(void);     // init LCD display
void LCD_ph1(char data);  // sends ascii of a single hex digit to display
void LCD_char(char data); // sends ascii character to display
void LCD_icmd(char data); //  sends 8 bit command (init till set to 4 bits)
void LCD_cmd(char data); // sends command to 4 bit interface nibble by nibble
void LCD_dec(char data); // displays byte as decimal number
void LCD_dec(short data);
void LCD_dec(unsigned short data);
void LCD_hex(char data);  // displays byte as hex number
void LCD_hex(short data);  // displays byte as hex number
void LCD_hex(unsigned short data);  // displays byte as hex number
void LCD_int(char data);
void LCD_int(short data);
void LCD_nib(char data);
void LCD_bin(char data);  // displays byte as binary number
void LCD_bin(unsigned short data);  // displays byte as binary number
void LCD_init(void);     //initializes LDC display
void LCD_printf( const char* text ); //sends ascii string to display
void LCD_setpos(char line, char pos); //sets potition on display
void LCD_clear(void);    // clear LCD Screen

#endif //_EESD_H_

